import {ResDataType} from "./ajax";
import  axios from "./ajax"

type searchDataType={
    keyword : string,
    isStar:boolean,
    isDeleted:boolean,
    page:number,
    pageSize:number
    //会添加其他的搜索关键项
}


//获取单个问卷的信息
export async function getQuestionServe(id:string): Promise<ResDataType> {
    const url = `/api/question/${id}`;
    const result = (await axios.get(url)) as ResDataType;
    console.log(JSON.stringify(result)+"????");
    return result;
}
//创建新问卷
export async function createQuestionService(): Promise<ResDataType> {
    const url = `/api/question`;
    const result = (await axios.post(url)) as ResDataType;
    return result;
}
export async function getQuestionListService( opt:Partial<searchDataType> = {}): Promise<ResDataType> {
    const url = `/api/question`;
    const result = (await axios.get(url,{params:opt})) as ResDataType;
    return result;
}

//跟新单个问卷
export async function UpdateQuestionService( id:string,opt:{[key:string]:any}): Promise<ResDataType> {
    const url = `/api/question/${id}`;
    const result = (await axios.patch(url,opt)) as ResDataType;
    return result;
}
//复制问卷
export async function DuplicateQuestionService( id:string): Promise<ResDataType> {
    const url = `/api/question/duplicate/${id}`;
    const result = (await axios.post(url)) as ResDataType;
    return result;
}
//彻底批量删除问卷
export async function deleteQuestionListService( ids:string[]): Promise<ResDataType> {
    const url = `/api/question`;
    const result = (await axios.delete(url,{data:ids})) as ResDataType;
    return result;
}
